package com.socket.controller;

import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.time.LocalDateTime;

/*@Component
@Configuration      //1.主要用于标记配置类，兼备Component的效果。
@EnableScheduling */  // 2.开启定时任务

@RestController
@RequestMapping("task")
public class SaticScheduleTask {
    WebSocketServer webSocketServer;
    //3.添加定时任务
    /*@Scheduled(cron = "0/10 * * * * ?")*/
    //或直接指定时间间隔，例如：5秒
    //@Scheduled(fixedRate=5000)
    /*private void configureTasks() throws IOException {
        webSocketServer.sendMessage("执行静态定时任务时间:xiaoxi " );
    }*/


    @RequestMapping("many")
    public String helloManyWebSocket() throws IOException{
        //向所有人发送消息
        webSocketServer.sendMessage("你好~！");

        return "发送成功";
    }

    @RequestMapping("one")
    public String helloOneWebSocket(String sessionId) throws IOException {
        //向某个人发送消息
        webSocketServer.sendInfo("你好~！，单个用户","小花");

        return "发送成功";
    }

}
